.class public Lcom/burstly/lib/util/ScreenOrientationManager;
.super Ljava/lang/Object;
.source "ScreenOrientationManager.java"


# annotations
.annotation build Landroid/annotation/SuppressLint;
    value = {
        "NewApi"
    }
.end annotation


# static fields
.field public static final LANDSCAPE:Ljava/lang/String; = "landscape"

.field public static final NONE:Ljava/lang/String; = "none"

.field public static final PORTRAIT:Ljava/lang/String; = "portrait"


# instance fields
.field private final mActivityRef:Ljava/lang/ref/Reference;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/lang/ref/Reference",
            "<",
            "Landroid/app/Activity;",
            ">;"
        }
    .end annotation
.end field

.field private final mDefaultOrientation:I


# direct methods
.method public constructor <init>(Landroid/app/Activity;)V
    .locals 1
    .parameter "targetActivity"

    .prologue
    .line 65
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 66
    new-instance v0, Ljava/lang/ref/WeakReference;

    invoke-direct {v0, p1}, Ljava/lang/ref/WeakReference;-><init>(Ljava/lang/Object;)V

    iput-object v0, p0, Lcom/burstly/lib/util/ScreenOrientationManager;->mActivityRef:Ljava/lang/ref/Reference;

    .line 67
    invoke-virtual {p1}, Landroid/app/Activity;->getRequestedOrientation()I

    move-result v0

    iput v0, p0, Lcom/burstly/lib/util/ScreenOrientationManager;->mDefaultOrientation:I

    .line 68
    return-void
.end method

.method private static changeToLandscape(Landroid/app/Activity;)V
    .locals 1
    .parameter "activity"

    .prologue
    .line 113
    invoke-static {}, Lcom/burstly/lib/util/ScreenOrientationManager;->isApiHigher9()Z

    move-result v0

    if-eqz v0, :cond_0

    .line 114
    const/4 v0, 0x6

    invoke-virtual {p0, v0}, Landroid/app/Activity;->setRequestedOrientation(I)V

    .line 118
    :goto_0
    return-void

    .line 116
    :cond_0
    const/4 v0, 0x0

    invoke-virtual {p0, v0}, Landroid/app/Activity;->setRequestedOrientation(I)V

    goto :goto_0
.end method

.method private static changeToPortrait(Landroid/app/Activity;)V
    .locals 1
    .parameter "activity"

    .prologue
    .line 126
    invoke-static {}, Lcom/burstly/lib/util/ScreenOrientationManager;->isApiHigher9()Z

    move-result v0

    if-eqz v0, :cond_0

    .line 127
    const/4 v0, 0x7

    invoke-virtual {p0, v0}, Landroid/app/Activity;->setRequestedOrientation(I)V

    .line 131
    :goto_0
    return-void

    .line 129
    :cond_0
    const/4 v0, 0x1

    invoke-virtual {p0, v0}, Landroid/app/Activity;->setRequestedOrientation(I)V

    goto :goto_0
.end method

.method private static isApiHigher9()Z
    .locals 2

    .prologue
    .line 139
    sget v0, Landroid/os/Build$VERSION;->SDK_INT:I

    const/16 v1, 0x9

    if-lt v0, v1, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method


# virtual methods
.method public restoreDefaultOrientation()V
    .locals 2

    .prologue
    .line 147
    iget-object v1, p0, Lcom/burstly/lib/util/ScreenOrientationManager;->mActivityRef:Ljava/lang/ref/Reference;

    invoke-virtual {v1}, Ljava/lang/ref/Reference;->get()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/app/Activity;

    .line 148
    .local v0, activity:Landroid/app/Activity;
    if-nez v0, :cond_0

    .line 152
    :goto_0
    return-void

    .line 151
    :cond_0
    iget v1, p0, Lcom/burstly/lib/util/ScreenOrientationManager;->mDefaultOrientation:I

    invoke-virtual {v0, v1}, Landroid/app/Activity;->setRequestedOrientation(I)V

    goto :goto_0
.end method

.method public setOrientation(Ljava/lang/String;Z)V
    .locals 3
    .parameter "desiredOrientation"
    .parameter "allowOrientationChange"

    .prologue
    .line 77
    iget-object v2, p0, Lcom/burstly/lib/util/ScreenOrientationManager;->mActivityRef:Ljava/lang/ref/Reference;

    invoke-virtual {v2}, Ljava/lang/ref/Reference;->get()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/app/Activity;

    .line 78
    .local v0, activity:Landroid/app/Activity;
    if-nez v0, :cond_1

    .line 96
    :cond_0
    :goto_0
    return-void

    .line 81
    :cond_1
    const-string v2, "portrait"

    invoke-virtual {v2, p1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v2

    if-eqz v2, :cond_3

    .line 82
    invoke-static {v0}, Lcom/burstly/lib/util/ScreenOrientationManager;->changeToPortrait(Landroid/app/Activity;)V

    .line 93
    :cond_2
    :goto_1
    if-eqz p2, :cond_0

    .line 94
    const/4 v2, -0x1

    invoke-virtual {v0, v2}, Landroid/app/Activity;->setRequestedOrientation(I)V

    goto :goto_0

    .line 83
    :cond_3
    const-string v2, "landscape"

    invoke-virtual {v2, p1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v2

    if-eqz v2, :cond_4

    .line 84
    invoke-static {v0}, Lcom/burstly/lib/util/ScreenOrientationManager;->changeToLandscape(Landroid/app/Activity;)V

    goto :goto_1

    .line 85
    :cond_4
    if-nez p2, :cond_2

    .line 86
    invoke-virtual {v0}, Landroid/app/Activity;->getResources()Landroid/content/res/Resources;

    move-result-object v2

    invoke-virtual {v2}, Landroid/content/res/Resources;->getConfiguration()Landroid/content/res/Configuration;

    move-result-object v2

    iget v1, v2, Landroid/content/res/Configuration;->orientation:I

    .line 87
    .local v1, currentOrientation:I
    const/4 v2, 0x2

    if-ne v1, v2, :cond_5

    .line 88
    invoke-static {v0}, Lcom/burstly/lib/util/ScreenOrientationManager;->changeToLandscape(Landroid/app/Activity;)V

    goto :goto_1

    .line 90
    :cond_5
    invoke-static {v0}, Lcom/burstly/lib/util/ScreenOrientationManager;->changeToPortrait(Landroid/app/Activity;)V

    goto :goto_1
.end method

.method public setOrientation(Z)V
    .locals 1
    .parameter "allowOrientationChange"

    .prologue
    .line 104
    const-string v0, "none"

    invoke-virtual {p0, v0, p1}, Lcom/burstly/lib/util/ScreenOrientationManager;->setOrientation(Ljava/lang/String;Z)V

    .line 105
    return-void
.end method
